﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {

    public class ASColor {

        public static const WHITE:ASColor = new ASColor(0xFFFFFF);
;
        public static const LIGHT_GRAY:ASColor = new ASColor(0xC0C0C0);
;
        public static const GRAY:ASColor = new ASColor(0x808080);
;
        public static const DARK_GRAY:ASColor = new ASColor(0x404040);
;
        public static const BLACK:ASColor = new ASColor(0);
;
        public static const RED:ASColor = new ASColor(0xFF0000);
;
        public static const PINK:ASColor = new ASColor(16756655);
;
        public static const ORANGE:ASColor = new ASColor(0xFFC800);
;
        public static const HALO_ORANGE:ASColor = new ASColor(0xFFC200);
;
        public static const YELLOW:ASColor = new ASColor(0xFFFF00);
;
        public static const GREEN:ASColor = new ASColor(0xFF00);
;
        public static const HALO_GREEN:ASColor = new ASColor(8453965);
;
        public static const MAGENTA:ASColor = new ASColor(0xFF00FF);
;
        public static const CYAN:ASColor = new ASColor(0xFFFF);
;
        public static const BLUE:ASColor = new ASColor(0xFF);
;
        public static const HALO_BLUE:ASColor = new ASColor(2881013);
;

        protected var rgb:uint;
        protected var alpha:Number;
        protected var hue:Number;
        protected var luminance:Number;
        protected var saturation:Number;
        private var hlsCounted:Boolean;

        public function ASColor(_arg1:uint=0, _arg2:Number=1){
            this.rgb = _arg1;
            this.alpha = Math.min(1, Math.max(0, _arg2));
            this.hlsCounted = false;
        }
        public static function getASColor(_arg1:uint, _arg2:uint, _arg3:uint, _arg4:Number=1):ASColor{
            return (new ASColor(getRGBWith(_arg1, _arg2, _arg3), _arg4));
        }
        public static function getWithARGB(_arg1:uint):ASColor{
            var _local2:uint = (_arg1 & 0xFFFFFF);
            var _local3:Number = ((_arg1 >>> 24) / 0xFF);
            return (new ASColor(_local2, _local3));
        }
        public static function getASColorWithHLS(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number=1):ASColor{
            var _local9:Number;
            var _local10:Number;
            var _local11:Number;
            var _local12:Number;
            var _local13:Number;
            var _local5:ASColor = new ASColor(0, _arg4);
            _local5.hlsCounted = true;
            _local5.hue = Math.max(0, Math.min(1, _arg1));
            _local5.luminance = Math.max(0, Math.min(1, _arg2));
            _local5.saturation = Math.max(0, Math.min(1, _arg3));
            var _local6:Number = _local5.hue;
            var _local7:Number = _local5.luminance;
            var _local8:Number = _local5.saturation;
            _local10 = 0;
            _local9 = _local10;
            _local6 = (_local6 * 360);
            if (_local7 < 0.5){
                _local10 = (_local7 * (1 + _local8));
            } else {
                _local10 = ((_local7 + _local8) - (_local7 * _local8));
            };
            _local9 = ((2 * _local7) - _local10);
            if (_local8 == 0){
                _local11 = _local7;
                _local12 = _local7;
                _local13 = _local7;
            } else {
                _local11 = hlsValue(_local9, _local10, (_local6 + 120));
                _local12 = hlsValue(_local9, _local10, _local6);
                _local13 = hlsValue(_local9, _local10, (_local6 - 120));
            };
            _local11 = (_local11 * 0xFF);
            _local12 = (_local12 * 0xFF);
            _local13 = (_local13 * 0xFF);
            var _local14:Number = (((_local11 << 16) + (_local12 << 8)) + _local13);
            var _local15:uint = Math.max(0, Math.min(0xFFFFFF, Math.round(_local14)));
            _local5.rgb = _local15;
            return (_local5);
        }
        private static function hlsValue(_arg1:Number, _arg2:Number, _arg3:Number):Number{
            if (_arg3 > 360){
                _arg3 = (_arg3 - 360);
            };
            if (_arg3 < 0){
                _arg3 = (_arg3 + 360);
            };
            if (_arg3 < 60){
                return ((_arg1 + (((_arg2 - _arg1) * _arg3) / 60)));
            };
            if (_arg3 < 180){
                return (_arg2);
            };
            if (_arg3 < 240){
                return ((_arg1 + (((_arg2 - _arg1) * (240 - _arg3)) / 60)));
            };
            return (_arg1);
        }
        public static function getRGBWith(_arg1:uint, _arg2:uint, _arg3:uint):uint{
            var _local4:uint = _arg1;
            var _local5:uint = _arg2;
            var _local6:uint = _arg3;
            if (_local4 > 0xFF){
                _local4 = 0xFF;
            };
            if (_local5 > 0xFF){
                _local5 = 0xFF;
            };
            if (_local6 > 0xFF){
                _local6 = 0xFF;
            };
            var _local7:uint = (((_local4 << 16) + (_local5 << 8)) + _local6);
            return (_local7);
        }

        public function getAlpha():Number{
            return (this.alpha);
        }
        public function getRGB():uint{
            return (this.rgb);
        }
        public function getARGB():uint{
            var _local1:uint = (this.alpha * 0xFF);
            return ((this.rgb | (_local1 << 24)));
        }
        public function getRed():uint{
            return (((this.rgb & 0xFF0000) >> 16));
        }
        public function getGreen():uint{
            return (((this.rgb & 0xFF00) >> 8));
        }
        public function getBlue():uint{
            return ((this.rgb & 0xFF));
        }
        public function getHue():Number{
            this.countHLS();
            return (this.hue);
        }
        public function getLuminance():Number{
            this.countHLS();
            return (this.luminance);
        }
        public function getSaturation():Number{
            this.countHLS();
            return (this.saturation);
        }
        private function countHLS():void{
            var _local4:Number;
            var _local5:Number;
            var _local6:Number;
            var _local7:Number;
            var _local8:Number;
            var _local9:Number;
            var _local10:Number;
            var _local11:Number;
            var _local12:Number;
            var _local13:Number;
            if (this.hlsCounted){
                return;
            };
            this.hlsCounted = true;
            var _local1:Number = (this.getRed() / 0xFF);
            var _local2:Number = (this.getGreen() / 0xFF);
            var _local3:Number = (this.getBlue() / 0xFF);
            _local13 = 0;
            _local12 = _local13;
            _local11 = _local12;
            if (_local1 > 0){
                _local11 = _local1;
            };
            if (_local11 > 1){
                _local11 = 1;
            };
            if (_local2 > 0){
                _local12 = _local2;
            };
            if (_local12 > 1){
                _local12 = 1;
            };
            if (_local3 > 0){
                _local13 = _local3;
            };
            if (_local13 > 1){
                _local13 = 1;
            };
            _local7 = _local11;
            if (_local12 < _local7){
                _local7 = _local12;
            };
            if (_local13 < _local7){
                _local7 = _local13;
            };
            _local8 = _local11;
            if (_local12 > _local8){
                _local8 = _local12;
            };
            if (_local13 > _local8){
                _local8 = _local13;
            };
            _local6 = 0;
            _local5 = _local6;
            _local4 = _local5;
            _local10 = (_local8 - _local7);
            _local9 = (_local8 + _local7);
            this.luminance = (0.5 * _local9);
            if (_local8 != _local7){
                _local4 = ((_local8 - _local11) / _local10);
                _local5 = ((_local8 - _local12) / _local10);
                _local6 = ((_local8 - _local13) / _local10);
            } else {
                this.saturation = (this.hue = 0);
                return;
            };
            if (this.luminance < 0.5){
                this.saturation = (_local10 / _local9);
            } else {
                this.saturation = (_local10 / (2 - _local9));
            };
            if (_local11 == _local8){
                this.hue = (60 * ((6 + _local6) - _local5));
            } else {
                if (_local12 == _local8){
                    this.hue = (60 * ((2 + _local4) - _local6));
                } else {
                    this.hue = (60 * ((4 + _local5) - _local4));
                };
            };
            if (this.hue > 360){
                this.hue = (this.hue - 360);
            };
            this.hue = (this.hue / 360);
        }
        public function changeAlpha(_arg1:Number):ASColor{
            return (new ASColor(this.getRGB(), _arg1));
        }
        public function changeHue(_arg1:Number):ASColor{
            return (getASColorWithHLS(_arg1, this.getLuminance(), this.getSaturation(), this.getAlpha()));
        }
        public function changeLuminance(_arg1:Number):ASColor{
            return (getASColorWithHLS(this.getHue(), _arg1, this.getSaturation(), this.getAlpha()));
        }
        public function changeSaturation(_arg1:Number):ASColor{
            return (getASColorWithHLS(this.getHue(), this.getLuminance(), _arg1, this.getAlpha()));
        }
        public function scaleHLS(_arg1:Number, _arg2:Number, _arg3:Number):ASColor{
            var _local4:Number = (this.getHue() * _arg1);
            var _local5:Number = (this.getLuminance() * _arg2);
            var _local6:Number = (this.getSaturation() * _arg3);
            return (getASColorWithHLS(_local4, _local5, _local6, this.alpha));
        }
        public function offsetHLS(_arg1:Number, _arg2:Number, _arg3:Number):ASColor{
            var _local4:Number = (this.getHue() + _arg1);
            if (_local4 > 1){
                _local4--;
            };
            if (_local4 < 0){
                _local4 = (_local4 + 1);
            };
            var _local5:Number = (this.getLuminance() + _arg2);
            var _local6:Number = (this.getSaturation() + _arg3);
            return (getASColorWithHLS(_local4, _local5, _local6, this.alpha));
        }
        public function darker(_arg1:Number=0.7):ASColor{
            var _local2:uint = this.getRed();
            var _local3:uint = this.getGreen();
            var _local4:uint = this.getBlue();
            return (getASColor((_local2 * _arg1), (_local3 * _arg1), (_local4 * _arg1), this.alpha));
        }
        public function brighter(_arg1:Number=0.7):ASColor{
            var _local2:uint = this.getRed();
            var _local3:uint = this.getGreen();
            var _local4:uint = this.getBlue();
            var _local5:Number = Math.floor((1 / (1 - _arg1)));
            if ((((((_local2 == 0)) && ((_local3 == 0)))) && ((_local4 == 0)))){
                return (getASColor(_local5, _local5, _local5, this.alpha));
            };
            if ((((_local2 > 0)) && ((_local2 < _local5)))){
                _local2 = _local5;
            };
            if ((((_local3 > 0)) && ((_local3 < _local5)))){
                _local3 = _local5;
            };
            if ((((_local4 > 0)) && ((_local4 < _local5)))){
                _local4 = _local5;
            };
            return (getASColor((_local2 / _arg1), (_local3 / _arg1), (_local4 / _arg1), this.alpha));
        }
        public function toString():String{
            return ((((("ASColor(rgb:" + this.rgb.toString(16)) + ", alpha:") + this.alpha) + ")"));
        }
        public function equals(_arg1:Object):Boolean{
            var _local2:ASColor = (_arg1 as ASColor);
            if (_local2 != null){
                return ((((_local2.alpha === this.alpha)) && ((_local2.rgb === this.rgb))));
            };
            return (false);
        }
        public function clone():ASColor{
            return (new ASColor(this.getRGB(), this.getAlpha()));
        }

    }
}//package org.aswing 
